import { Component, Injector, ViewEncapsulation, ViewChild, ElementRef, OnInit } from '@angular/core';
import { AppComponentBase } from '@shared/common/app-component-base';
import { PipelineNodesServiceProxy, WorkingTimeServiceProxy, NodeWorkerForPipleinOutput } from '@shared/service-proxies/service-proxies';
import { appModuleAnimation } from '@shared/animations/routerTransition';
import { Table } from 'primeng/components/table/table';
import { Paginator } from 'primeng/components/paginator/paginator';
import { LazyLoadEvent } from 'primeng/components/common/lazyloadevent';
import * as moment from 'moment';
import { finalize } from 'rxjs/operators';
import { CreateOrEditTaskworkingModalComponent } from './create-or-edit-taskworking-modal.component';
import { MenuItem } from 'primeng/api';

@Component({
  templateUrl: './taskworking.component.html',
  encapsulation: ViewEncapsulation.None,
  animations: [appModuleAnimation()]
})

export class TaskworkingComponent extends AppComponentBase implements OnInit {
  @ViewChild('dataTable') dataTable: Table;
  @ViewChild('paginator') paginator: Paginator;

  dateRange: Date[];
  advancedFiltersAreShown = false;
  work: NodeWorkerForPipleinOutput[];
  en: any;
  filterText = '';

  constructor(
    injector: Injector,
    private _workingTimeServiceProxy: WorkingTimeServiceProxy,
    private _taskServiceProxy: PipelineNodesServiceProxy,
  ) {
    super(injector);
  }

  ngOnInit() {

    // this.en = {
    //   firstDayOfWeek: 0,
    //   monthNames: ["1月", "2月", "3月", "4月", "5月", "6月", "7月", "8月", "9月", "10月", "11月", "12月"],
    //   monthNamesShort: ["1月", "2月", "3月", "4月", "5月", "6月", "7月", "8月", "9月", "10月", "11月", "12月"],
    //   dateFormat: 'yy-mm',
    //   weekHeader: 'Wk'
    // };
  }
  getWorking(event?: LazyLoadEvent) {
    this.primengTableHelper.showLoadingIndicator();
    var start=null;
      var end=null;
    if(this.dateRange!=undefined)
    {
      start=moment(this.dateRange[0]);
      end=moment(this.dateRange[1]);
    }
    this._workingTimeServiceProxy.getPipelineWorkers(
      this.filterText,
      "51",
      start,
      end,
      this.primengTableHelper.getSorting(this.dataTable),
      this.primengTableHelper.getMaxResultCount(this.paginator, event),
      this.primengTableHelper.getSkipCount(this.paginator, event)
    ).subscribe(result => {
        console.log(result.items);
      this.primengTableHelper.totalRecordsCount = result.totalCount;
      this.primengTableHelper.records = result.items;
      this.primengTableHelper.hideLoadingIndicator();
    });
  }
  remWorking()
  {
    this.dateRange=undefined;
    this.getWorking();
  }
  deleteModel(id:string){
    this.message.confirm('确认删除该条型号计划吗？', isConfirmed => {
        if (isConfirmed) {
            this._taskServiceProxy.delNodework(id).subscribe(() => {
                this.notify.success(this.l('SuccessfullyDeleted'));
                this.getWorking();
            });
        }
    });
  }
}
